<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>工程竣工验收 - 编写竣工验收情况</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Expires" CONTENT="0">
    <meta http-equiv="Cache-Control" content="no-siteapp,no-transform,no-store, no-cache, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="/static/css/buildUnit/common.css">
    <style>
        body {
            height: auto;
        }

        .content {
            padding: 20px;
        }
        .layui-container {
            padding-top: 20px;
            width: auto;;
        }

        /*单元格备注样式*/
        .layui-table td.tdBz {
            text-align: left;
            padding-left: 0;
            border-left: none;
            color: #aaa;
        }

        .padNone .layui-form-select .layui-input {
            padding-right: 0;
        }

        .hide {
            display: none;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <form id="form1" class="layui-form layui-form-pane" action="" lay-filter="example1">
        <!--验收领导小组-->
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">验收领导小组</h2>
                <div class="layui-colla-content layui-show">
                    <table class="layui-table v-table">
                        <tbody>
                        <tr class="hide">
                            <td width="24%"></td>
                            <td width="13%"></td>
                            <td width="13%"></td>
                            <td width="24%"></td>
                            <td width="13%"></td>
                            <td width="13%"></td>
                        </tr>
                        <tr>
                            <td class="th8">组长</td>
                            <td colspan="2">
                                <input name="leader" lay-verify="isEmpty" class="layui-input formData1" placeholder="组长名称" autocomplete="off" readonly>
                            </td>
                            <td class="th8">副组长</td>
                            <td colspan="2">
                                <input name="deputyLeader" lay-verify="isEmpty" class="layui-input formData1" placeholder="副组长名称" autocomplete="off" readonly>
                            </td>
                        </tr>
                        <tr>
                            <td class="th8 required">成员</td>
                            <td colspan="5">
                                <input name="members" lay-verify="isEmpty|uname" class="layui-input formData1" placeholder="成员名称" autocomplete="off" readonly>
                            </td>
                        </tr>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!--各专业验收组-->
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">各专业验收组</h2>
                <div class="layui-colla-content layui-show">
                    <script type="text/html" id="toolbarOrg">
                        <div class="layui-btn-container">
                        </div>
                    </script>
                    <table class="layui-hide" id="dataList" lay-filter="dataList"></table>
                </div>
            </div>
        </div>
    </form>

    <form id="form" class="layui-form layui-form-pane" action="" lay-filter="example">
        <input type="hidden" name="id" class="formData" value="">
        <input type="hidden" name="cptId" class="formData" value="">
        <!--竣工验收结论-->
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">竣工验收结论</h2>
                <div class="layui-colla-content layui-show">
                    <table class="layui-table v-table">
                        <tbody>
                        <tr class="hide">
                            <td width="24%"></td>
                            <td width="13%"></td>
                            <td width="13%"></td>
                            <td width="24%"></td>
                            <td width="13%"></td>
                            <td width="13%"></td>
                        </tr>
                        <tr>
                            <td class="th8 required">竣工验收结论</td>
                            <td colspan="5">
                                <textarea rows="5" cols="" class="layui-textarea formData" name="conclusion" id="conclusion" autocomplete="off"></textarea>
                            </td>
                        </tr>

                        </tbody>
                    </table>
                    <input type="button" id="sign1" value="各单位责任人签字盖章" class="layui-btn" style="display:none" lay-filter="sign1">
                    <input type="button" id="sign11" value="重新签字盖章" class="layui-btn" style="display:none" lay-filter="sign11">
                    <input type="button" id="download1" value="下载附件" style="display:none" lay-filter="download1" class="layui-btn layui-btn-xs">
                </div>
            </div>
        </div>

    </form>
</div>
<script src="/static/js/main.js"></script>
<script type="text/javascript">
    var $;
    layui.use(['jquery', 'element', 'form', 'laydate', 'configure', 'configureCom', 'selectFun', 'bluebird', 'replaceStr', 'jsDictFile', 'mapExtend'], function () {
        $ = layui.jquery;
        var element = layui.element;
        var form = layui.form;
        var configure = layui.configure;
        var table = layui.table;
        var configureCom = layui.configureCom;
        var laydate = layui.laydate;
        var selectFun = layui.selectFun;
        var sessionFun = layui.sessionFun;//存储session
        var listData = sessionFun.get(configure.COMPLETION_ROW_DATA);
        var token = sessionFun.get(configure.SESSION_TOKEN) ? sessionFun.get(configure.SESSION_TOKEN).token : '';
        var cptStatus = sessionFun.get( 'CPT_STATUS');

        var cptAcceptanceId = sessionFun.get('cptAcceptanceId');

        //申请记录进来的, 赋值申请ID
        if (listData) {
            cptAcceptanceId = listData.id;
        }
        //根据申请ID查询条件核查记录
        var res={};
        var data1 = $.extend({cptAcceptanceId:cptAcceptanceId}, {token: token});
        var index = top.layer.load(1, {shade: 0.01});
        $.ajax({
            url: configure.CPT_ACCEPTANCE_CONCLUSION_VIEW_API,
            type: 'get',
            cache: false,
            async:false,
            data: data1,
            dataType: 'json',
            success: function (data) {
                top.layer.close(index);
                res = data;
            },
            error: function (data) {
                top.layer.close(index);
            }
        });

        //如果查到条件核查记录表单赋值
        if(res.data && res.data.id){
            form.val('example', res.data);
        }else{
            //如果没有查到核查记录 则为新增, 表单赋值仅有申请ID
            var newData = { cptId: cptAcceptanceId};
            form.val('example', newData);
        }

        /**
         * 初始化专业验收小组
         */
        var cols = [[
            {field: 'specialty', title: '专业名称'},
            {field: 'leader', title: '组长' },
            {field: 'members', title: '组员'},
        ]];
        configureCom.tableRenderGet(configure.CPT_ACCEPTANCE_TEAM_LIST_API, {cptId: cptAcceptanceId}, cols, 'dataList', 10, '', 'toolbarOrg',false);

        /**
         * 初始化 竣工申请小组情况
         */
        var res={};
        var data1 = $.extend({cptAcceptanceId:cptAcceptanceId}, {token: token});
        var index = top.layer.load(1, {shade: 0.01});
        $.ajax({
            url: configure.COMPLETION_DETAIL_INFO,
            type: 'get',
            cache: false,
            async:false,
            data: data1,
            dataType: 'json',
            success: function (data) {
                top.layer.close(index);
                res = data;
                if(res.data){
                    form.val('example1', res.data);
                }else{
                    console.log("未找到 竣工验收申请记录, cptAcceptanceId:"+cptAcceptanceId);
                }
            },
            error: function (data) {
                top.layer.close(index);
            }
        });


        //监听下载1
        $("#download1").click(function(data){
            window.open("/api/cpt/acceptance/conclusion/bxjgysqk1File/sign/download?token="+token + "&cptId="+cptAcceptanceId);
        });


        //监听签名1
        $("#sign1").click(function(data){
            //TODO 后台根据模板生成pdf文件
            var res1 = null;
            var data1 = {id:cptAcceptanceId, reSign:0};
            $.ajax({
                url: '/api/cpt/acceptance/conclusion/bxjgysqk1File/create?token='+token,
                type: 'post',
                cache: false,
                async:false,
                contentType : 'application/json',
                dataType : 'json',
                data :JSON.stringify(data1),
                success: function (data) {
                    res1 = data;
                    layer.closeAll('loading');
                },
                error: function (data) {
                    layer.closeAll('loading');
                    layer.msg(data.msg?data.msg:"操作失败");
                }
            });

            //查询竣工验收详情, 并判断状态, 是否显示保存按钮
            if(res1 && res1.code==0){
                sessionFun.set(configure.SESSION_SIGN_DATA,{id:cptAcceptanceId, fileName:res1.data.fileName, attId:res1.data.attId});
                //打开插件工具, 盖章上传
                top.layer.open({
                    type: 2,
                    title: '上传附件',
                    content: 'pages/completion/sign/bxjgysqk1Sign.html',
                    area: configureCom.Psize1,
                    cancel: function (index, layero) {
//                        configureCom.tableReloadById(table12.id);
                    },
                    btn: ['保存签章'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.signSave().then(function (res) {
                            if (res.code == 1) {
                                top.layer.msg(res.msg);
                                top.layer.close(index);
                                configureCom.tableReloadById(table12.id);
                            } else {
                                top.layer.alert(res.msg);
                            }
                        });
                    }
                });
            }else if(res1.code){
                layer.msg(res1.msg?res1.msg:"操作失败.");
                return;
            }else{
                layer.msg("操作失败!");
                return;
            }
        });


        //监听重新签名
        $("#sign11").click(function(data){
            //TODO 后台根据模板生成pdf文件
            var res1 = null;
            var data1 = {id:cptAcceptanceId, reSign:1};
            $.ajax({
                url: '/api/cpt/acceptance/conclusion/bxjgysqk1File/create?token='+token,
                type: 'post',
                cache: false,
                async:false,
                contentType : 'application/json',
                dataType : 'json',
                data :JSON.stringify(data1),
                success: function (data) {
                    res1 = data;
                    layer.closeAll('loading');
                },
                error: function (data) {
                    layer.closeAll('loading');
                    layer.msg(data.msg?data.msg:"操作失败");
                }
            });

            //查询竣工验收详情, 并判断状态, 是否显示保存按钮
            if(res1 && res1.code==0){
                sessionFun.set(configure.SESSION_SIGN_DATA,{id:cptAcceptanceId, fileName:res1.data.fileName, attId:res1.data.attId});
                //打开插件工具, 盖章上传
                top.layer.open({
                    type: 2,
                    title: '上传附件',
                    content: 'pages/completion/sign/bxjgysqk1Sign.html',
                    area: configureCom.Psize1,
                    cancel: function (index, layero) {
//                        configureCom.tableReloadById(table12.id);
                    },
                    btn: ['保存签章'],
                    yes: function (index, layero) {
                        var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.signSave().then(function (res) {
                            if (res.code == 1) {
                                top.layer.msg(res.msg);
                                top.layer.close(index);
                                configureCom.tableReloadById(table12.id);
                            } else {
                                top.layer.alert(res.msg);
                            }
                        });
                    }
                });
            }else if(res1.code){
                layer.msg(res1.msg?res1.msg:"操作失败.");
                return;
            }else{
                layer.msg("操作失败!");
                return;
            }
        });

        //待办进入, 不显示下载按钮, 根据状态显示签字按钮
        if(sessionFun.get('cptAcceptanceId')){
            $("#download1").css("display","none");
            //2-竣工验收监督中
            if(cptStatus && cptStatus==3){
                $("#sign1").css("display","");
                $("#sign11").css("display","");
            }
        }else{
            //验收记录进入, 显示下载按钮, 不显示签字按钮
            $("#download1").css("display","");
            $("#sign1").css("display","none");
            $("#sign11").css("display","none");
        }




        form.render();
    });

    function getData() {
        return new Promise(function (res, rej) {
            var data = {};
            if (!window.formVerifyFun()) {
                //return false;
            }

            $('.formData').each(function (index, item) {
                var key = $(item).attr('name');
                var type = $(item).attr('type');
                if(type=='radio'){
                    data[key] = $("input[name='"+key+"']:checked").val();
                }else{
                    data[key] = $(item).val();
                }

            });
            res({result: data});
        });
    }

</script>
</body>
</html>
